package com.yulongtian.interviewWorks.day20220825;

/**
 * https://leetcode.cn/problems/three-in-one-lcci/
 *
 * @author YulongTian
 * @date 2022/8/25 - 15:26
 */
public class Test04 {

    public static void main(String[] args) {

    }

    //查看别人的方法
    class TripleInOne {
        int stackSize;
        int[] stack;

        public TripleInOne(int stackSize) {
            this.stackSize = stackSize;
            stack = new int[stackSize * 3 + 3];
            for (int i = 0; i < 3; i++) {
                stack[i] = 2 + stackSize * i;
            }
        }

        public void push(int stackNum, int value) {
            if (stack[stackNum] != (stackNum + 1) * stackSize + 2) {
                int top = stack[stackNum] + 1;
                stack[stackNum] += 1;
                stack[top] = value;
            }
        }

        public int pop(int stackNum) {
            if (stack[stackNum] == stackNum * stackSize + 2) {
                return -1;
            }
            int top = stack[stackNum];
            stack[stackNum] -= 1;
            return stack[top];
        }

        public int peek(int stackNum) {
            if (stack[stackNum] == stackNum * stackSize + 2) {
                return -1;
            }
            return stack[stack[stackNum]];
        }

        public boolean isEmpty(int stackNum) {
            return stack[stackNum] == stackNum * stackSize + 2;
        }
    }


}
